import { defineStore } from 'pinia';
import app from './app';
import { ref } from 'vue';
import { trimStart } from 'lodash';
const sys = defineStore(
	'sys',
	() => {
		let theme = ref('');
		let mode = ref('light');
		let modeAuto = ref(false);
		let fontSize = ref(1);
		let bgImg = ref('');
		let bgColor = ref('');
		let setTheme = (target = '') => {
			if (target === '') {
				// 设置页面主题... 应该根据setup内容区分
				theme.value = app().template?.setup.theme || 'orange';
			} else {
				theme.value = target;
			}
		};

		let setMode = (target = '') => {
			if (target) {
				mode.value = target;
			} else {
				mode.value = app().template?.setup.mode || 'light';
			}
		};

		let setFontSize = (target = 0) => {
			if (target === 0) {
				fontSize.value = app().template?.setup.fontSize || 30;
			} else {
				fontSize.value = target;
			}
		};

		let setBgImg = (target = '') => {
			// if (target) {
			// 	bgImg.value = target;
			// } else {
			// 	bgImg.value = app().template?.setup.bgImg;
			// }
		};

		let setBgColor = (target = '') => {
			// if (target) {
			// 	bgColor.value = target;
			// } else {
			// 	bgColor.value = app().template?.setup.bgColor;
			// }
		};

		return {
			theme,
			mode,
			modeAuto,
			fontSize,
			setTheme,
			setMode,
			setFontSize,
			setBgImg,
			setBgColor,
		};
	},
	{
		persist: {
			enabled: true,
		},
	},
);

export default sys;
